export const systemInfo = function () {
  const systemInformation = uni.getSystemInfoSync(); // 设备系统信息
  const scaleFactor = 750 / systemInformation.windowWidth; // 机型适配比例系数

  return {
    scaleFactor,
    ...systemInformation,
  };
};

export const getPageInfo = function ({ hasTitleBar } = { hasTitleBar: true }) {
  const { scaleFactor, windowHeight, statusBarHeight, safeArea }
    = systemInfo();

  // 默认值是55，如果pages.json中配置了tabBar，则需要改为新的高度
  const tabBarHeight = 55;
  const titleBarHeight = 44;
  const safeTop = safeArea ? safeArea.top : 0;
  let pageHeight = safeArea
    ? hasTitleBar
      ? safeArea.height - titleBarHeight
      : safeArea.height
    : hasTitleBar
      ? windowHeight - (statusBarHeight || 0) - titleBarHeight
      : windowHeight;

  // #ifdef H5 || MP-WEIXIN
  pageHeight = pageHeight - safeTop - 2; // 这里h5依然能滑动是因为外层的容器排版与uni-app的默认排版不同
  // #endif

  const pageInfo = {
    tabBarHeight,
    pageHeight,
    statusBarHeight,
    titleBarHeight,
    windowHeight,
    safeTop,
    safeArea,
    scaleFactor,
  };
  return pageInfo;
};
